package com.resource;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.List;

public class SAXResolveXml {

    public static void main(String[] args) {
        resolve();
    }

    public static void resolve() {
        InputStream inputStream = SAXResolveXml.class.getClassLoader().getResourceAsStream("xmlContext.xml");
        try {
            Document document = new SAXReader().read(inputStream);
            Element rootElement = document.getRootElement();

            List<Element> elements = rootElement.elements("bean");
            if (elements == null || elements.size() == 0) {
                throw new RuntimeException("无bean标签");
            }

            elements.forEach((Element x) -> {
                //获取Id
                String id = x.attributeValue("id"); //accountDao
                //获取权限定命名
                String clazz = x.attributeValue("class"); //com.udeam.edu.dao.impl.JdbcAccountDaoImpl
                // String scope = x.attributeValue("scope");
                //通过反射创建对象
                // Object o = Class.forName(clasz).newInstance();
                //存入ioc容器
                // iocMap.put(id, o);
                System.out.println("测试结果 beanName：" + id + ", beanClass：" + clazz);
            });

        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
